home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / cmds / cvs / dist / src / remove.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-02-06  |  2.1 KB  |  85 lines

  1. #ifndef lint
  2. static char rcsid[] = "$Id: remove.c,v 1.9 89/11/19 23:40:43 berliner Exp $";
  3. #endif !lint
  4.  
  5. /*
  6.  *    Copyright (c) 1989, Brian Berliner
  7.  *
  8.  *    You may distribute under the terms of the GNU General Public License
  9.  *    as specified in the README file that comes with the CVS 1.0 kit.
  10.  *
  11.  * Remove a File
  12.  *
  13.  *    Removes entries from the present version.
  14.  *    The entries will be removed from the RCS repository upon the
  15.  *    next "commit".
  16.  *
  17.  *    "remove" accepts no options, only file names that are to be
  18.  *    removed.  The file must not exist in the current directory
  19.  *    for "remove" to work correctly.
  20.  */
  21.  
  22. #include <sys/param.h>
  23. #include "cvs.h"
  24.  
  25. remove(argc, argv)
  26.     int argc;
  27.     char *argv[];
  28. {
  29.     register int i;
  30.     char fname[MAXPATHLEN];
  31.     int err = 0;
  32.  
  33.     if (argc == 1 || argc == -1)
  34.     remove_usage();
  35.     argc--;
  36.     argv++;
  37.     Name_Repository();
  38.     for (i = 0; i < argc; i++) {
  39.     (void) strcpy(User, argv[i]);
  40.     Version_TS(Rcs, Tag, User);
  41.     if (TS_User[0] != '\0') {
  42.         warn(0, "%s still exists", User);
  43.         err++;
  44.         continue;
  45.     }
  46.     if (VN_User[0] == '\0') {
  47.         warn(0, "there is no entry for %s", User);
  48.         err++;
  49.     } else if (VN_User[0] == '0' && VN_User[1] == '\0') {
  50.         /*
  51.          * It's a file that has been added, but not commited yet.
  52.          * So, remove the ,p and ,t file for it and scratch it from
  53.          * the entries file.
  54.          */
  55.         Scratch_Entry(User);
  56.         (void) sprintf(fname, "%s/%s%s", CVSADM, User, CVSEXT_OPT);
  57.         (void) unlink(fname);
  58.         (void) sprintf(fname, "%s/%s%s", CVSADM, User, CVSEXT_LOG);
  59.         (void) unlink(fname);
  60.     } else if (VN_User[0] == '-') {
  61.         /*
  62.          * It's already been flagged for removal, nothing more to do.
  63.          */
  64.         warn(0, "%s was already removed", User);
  65.         err++;
  66.     } else {
  67.         /*
  68.          * Re-register it with a negative version number.
  69.          */
  70.         (void) strcpy(fname, "-");
  71.         (void) strcat(fname, VN_User);
  72.         Register(User, fname, TS_Rcs);
  73.     }
  74.     }
  75.     Entries2Files();            /* and update the Files file */
  76.     exit(err);
  77. }
  78.  
  79. static
  80. remove_usage()
  81. {
  82.     (void) fprintf(stderr, "%s %s files...\n", progname, command);
  83.     exit(1);
  84. }
  85.